package com.itheima.advantagesup.controller;

import com.itheima.advantagesup.common.PaginationVO;
import com.itheima.advantagesup.common.R;
import com.itheima.advantagesup.entity.SysUser;
import com.itheima.advantagesup.service.SysUserService;
import com.itheima.advantagesup.vo.UserInfoVO;
import lombok.extern.slf4j.Slf4j;
import org.springframework.web.bind.annotation.*;

@RestController
@Slf4j
@RequestMapping("/sys_user")
public class UserController {
    private final SysUserService sysUserService;

    public UserController(SysUserService sysUserService) {
        this.sysUserService = sysUserService;
    }

    @GetMapping("/list")
    public R<PaginationVO<UserInfoVO>> page(String login_name, String status, String phone,
                                            @RequestParam(defaultValue = "1") String page,
                                            @RequestParam(defaultValue = "10") String limit) {
        //记录日志
        log.info("分页查询，参数：{},{},{},{},{}", login_name, status, phone, page, limit);
        //调用业务层分页查询功能
        PaginationVO<UserInfoVO> pages = sysUserService.page(login_name, status, phone, page, limit);
        return R.success(pages);
    }

    @PostMapping("/add")
    public R<?> addUser(@RequestBody UserInfoVO user) {
        log.info("添加用户参数：{}", user);
        sysUserService.addUser(user);
        return R.success("");
    }

    @PostMapping("/update")
    public R<?> aupdateUser(@RequestBody UserInfoVO user) {
        log.info("修改用户参数：{}", user);
        sysUserService.aupdateUser(user);
        return R.success("");
    }

    @GetMapping("/rowInfo")
    public R<UserInfoVO> rowInfoUser(String id) {
        log.info("用户详情参数：{}", id);
        UserInfoVO user = sysUserService.rowInfoUser(id);
        return R.success(user);
    }

    @GetMapping("/del")
    public R<?> delUser(String id) {
        log.info("用户删除参数：{}", id);
        sysUserService.delUser(id);
        return R.success("");
    }


}
